﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Weka
{
    internal class KeyValueListPair
    {
        //The First one is always the 
        public byte[] RawStructureData { get; set; }
        public ObjectDeserialiserProvider ObjectDeserialiserProvider { get; set; }
        public KeyValueListPair Next { get; set; }
        public KeyValueListPair CloneAndAdd(KeyValueListPair newOne)
        {
            KeyValueListPair next = (Next == null) ? newOne : Next.CloneAndAdd(newOne);
            return new KeyValueListPair() { Next = next, ObjectDeserialiserProvider = ObjectDeserialiserProvider, RawStructureData = RawStructureData };
        }

        public bool StructureMatches(Key key)
        {
            MemoryStream ms = key.Stream;

            if (ms.Length != RawStructureData.Length) return false;

            ms.Position = 0;
            for (int i = 0; i < RawStructureData.Length; i++)
                if (RawStructureData[i] != ((byte)ms.ReadByte())) return false;

            return true;
        }

    }
}
